<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import SubmitBtn from '@/components/SubmitBtn.vue'
import store from '@/store/index.js'

const formData = ref({
	appointmentId: "",
	comment: "", // 评价内容
	serviceRating: 5, // 服务评分
	processRating: 5, // 流程评分
	createdAt: "", // 提交时间
	userId: store.state.userid
})

const isDisabled = ref(false)

onLoad(options => {
	if (options.orderId) {
		formData.value.appointmentId = options.orderId
	}
	if (!options.data) return
	const data = JSON.parse(options.data)
	formData.value = { ...data }
	isDisabled.value = true
})

const confing = {
	api: '/logistics/evaluations',
	requiredFields: [
		{
			key: "appointmentId",
			name: " 关联id",
		}, {
			key: "comment",
			name: " 评价内容",
		},
	]
}
</script>

<template>
	<view class="carinfo page_container">
		<view class="content">
			<u-form :model="formData" label-width="200">
				<u-form-item label="评价内容:" required>
					<u-input :disabled="isDisabled" v-model="formData.comment" border type="textarea" placeholder="请输入评价内容" />
				</u-form-item>
				<u-form-item label="服务评分:">
					<u-rate :disabled="isDisabled" v-model="formData.serviceRating" inactive-icon="thumb-up"></u-rate>
				</u-form-item>
				<u-form-item label="处理流程评分:">
					<u-rate :disabled="isDisabled" v-model="formData.processRating" inactive-icon="thumb-up"></u-rate>
				</u-form-item>
				<u-form-item label="提交时间:" v-if="formData.id">
					<u-input disabled v-model="formData.createdAt" placeholder="请选择提交时间" />
				</u-form-item>
			</u-form>
		</view>
		<SubmitBtn v-bind="confing" :formData="formData" />
	</view>
</template>

<style lang="scss" scoped>
.carinfo {
	min-height: 100vh;
	background: #f5f5f5;
	padding-top: 20rpx;

	.content {
		background: #fff !important;
		border-radius: 20rpx;
		padding: 0 40rpx;
		margin-bottom: 100rpx;
	}
}
</style>